<?php 
include('../../../include/db.inc.php');
include('../../../cfg/cfg.inc.php');

session_start();

$db=new DbManager();
$db->connect(DBHOST, DBUSER, DBPWD,true,true,DBNAME,"");

function getFieldValue($db,$tableName,$pkRecord,$fieldName) {
    $sql="SELECT A.NAME,B.VALUE FROM cllg_tablefield A LEFT JOIN
            cllg_table_valuebyfield B ";
    $sql.=sprintf("ON (A.NAME=B.FK_TABLEFIELD AND B.PK_RECORD='%s') ",$pkRecord);
    $sql.=sprintf("WHERE B.FK_TABLEFIELD='%s' ",$fieldName);
    $sql.=sprintf("AND A.TABLE_NAME='%s' ",$tableName);
    //echo $sql;
    $rs=$db->fetch_all_array($db->query($sql));

    return $rs;
}
$fkEntity = 2;
$ciclo = $_GET["ciclo"];

$queryEstudiantes = "
select ID CARNET ,LAST_NAME,FIRST_NAME,SECOND_NAME,BIRTHDATE
from cllg_student
where ID IN ( select FK_STUDENT from cllg_student_assign b
        where b.FK_CYCLE=$ciclo and b.STATUS=0)
     or ID NOT IN ( select FK_STUDENT from cllg_student_assign b
    where b.FK_CYCLE=$ciclo and b.STATUS=1) ORDER BY LAST_NAME,FIRST_NAME";

$studentsResult = $db->queryToArray($queryEstudiantes);
$Fec = date('Y');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Alumnos Por Carrera</title>
        <link href="../../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="css/print.css" rel="stylesheet" type="text/css" />
       <script type="text/javascript" src="../../../js/prototype.js">
</script>
    </head>

    <body>
        <div id="wrap">

            <div id="header">
                <h1><legend>Listado Alumnos</legend></h1>
            </div>
            <div id="content">
                <h2><legend>Estudiantes Inactivos</legend></h2>
                <h2>Ciclo: <?=$ciclo?></h2>
                <table width="296" >
                    <tr>
                        <td id="noprint"><div id="no">
    <form id="form1" name="form1" method="post" action="">
      <input type="button" class="btn btn-info" name="printer" id="printer" value="Imprimir" onclick="$('no').hide();window.print();alert('Impresion Lista!');$('no').show();" />
        </form>
  </div>
                        </td>
                    </tr>
                </table>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" >

                    <tr>
                        <td colspan="8"><table width="100%" border="0" class="table table-bordered table-hover table-striped">
                                <tr>
                                    <td width="5%"><strong>Codigo</strong></td>
                                    <td width="28%"><strong>Nombre Alumno </strong></td>
                                    <td width="4%"><strong>Edad</strong></td>
                                    <td width="16%"><strong>Email</strong></td>
                                    <td width="11%"><strong>Telefonos</strong></td>
                                    <td width="18%"><strong>Empresa</strong></td>
                                    <td width="13%"><strong>Telefono Empresa</strong></td>
                                    <td width="5%"><strong>Tipo Sangre </strong></td>
                                </tr>
                                <?PHP
                                $c=0;
                                foreach($studentsResult as $rowStudent ){
                                    $c++;
                                    $mail=getFieldValue($db, "cllg_student",$rowStudent["CARNET"],"EMAIL");
                                    $t1=getFieldValue($db, "cllg_student",$rowStudent["CARNET"],"CELL_PHONE");
                                    $t2=getFieldValue($db, "cllg_student",$rowStudent["CARNET"],"HOME_TELEPHONE");
                                    $t4=getFieldValue($db, "cllg_student",$rowStudent["CARNET"],"WORK_TELEPHONE");
                                    $empresa=getFieldValue($db, "cllg_student",$rowStudent["CARNET"],"COMPANY_NAME");
                                    $tsangre=getFieldValue($db, "cllg_student",$rowStudent["CARNET"],"TIPO_SANGRE");
                                    ?><tr>
                                    <td height="28"><?= $c?></td>
                                    <td width="22%">
                                        <span class="Estilo1"><?PHP echo $rowStudent['LAST_NAME'];?>,&nbsp;
                                            <?PHP echo $rowStudent['FIRST_NAME'];?>
                                            <?PHP echo $rowStudent['SECOND_NAME'];?></span> </td>
                                    <td><?PHP echo $Fec-date('Y',strtotime($rowStudent['BIRTHDATE']));?></td>
                                    <td><?PHP echo $mail[0]["VALUE"];?></td>
                                    <td><?PHP echo $t1[0]["VALUE"];?>&nbsp;-&nbsp;<?PHP echo $t2[0]["VALUE"];?>&nbsp;                                    </td>
                                    <td><?PHP echo $empresa[0]["VALUE"];?></td>
                                    <td><?PHP echo $t4[0]["VALUE"];?></td>
                                    <td><?PHP echo $tsangre[0]["VALUE"];?></td>
                                </tr><?php }?>
                        </table></td>
                    </tr>
                    <tr>
                        <td width="14%">&nbsp;</td>
                        <td width="28%">&nbsp;</td>
                        <td width="6%">&nbsp;</td>
                        <td width="33%">&nbsp;</td>
                        <td width="76%" colspan="4" rowspan="2">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
                <hr />
            </div>
            <div id="footer">CINDE  - Generado el <?PHP echo $Fec;?></div>
        </div>
    </body>
</html>